#include <cstdlib>
#include "ourhdr.h"

Direction opposite(Direction d){
	switch (d){
		case LEFT:
			return RIGHT;
		case RIGHT:
			return LEFT;
		case UP:
			return DOWN;
		case DOWN:
			return UP;
	}
}

Pos&  Pos::operator=(const Pos &pos){
	m_row = pos.m_row;
	m_col = pos.m_col;
	return *this;
}

Direction operator-(const Pos &left, const Pos &right){
	if(right.isAboveOf(left))	return UP;
	if(right.isBelowOf(left))	return DOWN;
	if(right.isOnTheLeftOf(left)) return LEFT;
	if(right.isOnTheRightOf(left)) return RIGHT;
}

bool Pos::nextTo(const Pos &another) const{
	 return (abs(this->m_row - another.m_row) + abs(this->m_col - another.m_col) == 1);
}

bool Pos::isAboveOf(const Pos &another) const{
	return (this->m_row + 1 == another.m_row) && (this->m_col == another.m_col);
}

bool Pos::isBelowOf(const Pos &another) const{
	return (this->m_row - 1 == another.m_row) && (this->m_col == another.m_col);
}

bool Pos::isOnTheLeftOf(const Pos &another) const{
	return (this->m_row == another.m_row) && (this->m_col + 1 == another.m_col);
}

bool Pos::isOnTheRightOf(const Pos &another) const{
	return (this->m_row == another.m_row) && (this->m_col - 1 == another.m_col);
}
